<template>
    <div class="newsinfo-con">
        <!-- 大标题 -->
        <h3 class="title">{{newsinfo.title}}</h3>
        <!-- 子标题 -->
        <p class="subtitle">
            <span>发布时间:{{newsinfo.add_time | dataFomart}}</span>
            <span>点击次数:{{newsinfo.click}}</span>
        </p>
        <hr>
        <!-- 内容区 -->
        <div class="content" v-html="newsinfo.content"></div>
        <!-- 评论子组件 -->
        <comment-box :id=this.id></comment-box>
    </div>
</template>

<script>
import { Toast } from "mint-ui";
//导入评论子组件
import comment from "../subcomponents/comment.vue";
export default {
  data() {
    return {
      id: this.$route.params.id, //url传递过来的 id 挂载到data
      newsinfo: {}
    };
  },
  created() {
    this.getNewsinfo();
  },
  methods: {
    getNewsinfo() {
      this.$http.get("api/getnew/" + this.id).then(result => {
        if (result.body.status === 0) {
          this.newsinfo = result.body.message[0];
        } else {
          //失败
          Toast("获取新闻详情失败");
        }
      });
    }
  },
  components:{
      'comment-box':comment
  }
};
</script>

<style lang="sass">
.newsinfo-con{
    padding:0 5px;;
    .title{
        text-align:center;
        margin:15px 0;
        font-size:16px;
        color:red;
    }
    .subtitle{
        display:flex;
        justify-content: space-between;
        font-size:13px;
    }
    .content{
        img{
            width:100%;
        }
    }       
}
</style>
